#include <iostream>
#include <unistd.h>
#include <string>
#include <string.h>

#include "comm.hpp"
int main()
{
    if (mkfifo(filename, MODE) < 0)
    {
        Log("创建管道文件失败", Error);
        return 1;
    }
    Log("创建管道文件成功", Debug) << "step1" << std::endl;

    int fd = open(filename, O_RDONLY);
    if (fd < 0)
    {
        Log("打开管道文件失败", Error);
    }
    Log("打开管道文件成功", Debug) << "step2" << std::endl;

    char buffer[1024];
    while (strcmp(buffer, "quit") != 0)
    {
        int len = read(fd, buffer, sizeof(buffer));
        buffer[len] = '\0';
        std::cout << buffer << std::endl;
    }

    close(fd);
    Log("关闭管道文件成功", Debug) << "step3" << std::endl;

    unlink(filename);
    Log("删除管道文件成功", Debug) << "step4" << std::endl;

    return 0;
}
